Skip to content

fix: preserve Codex Responses headers#2494

Closed
cyhhao wants to merge 4 commits into
Wei-Shaw:mainfrom
cyhhao:fix/codex-beta-features
Closed

fix: preserve Codex Responses headers#2494
cyhhao wants to merge 4 commits into
Wei-Shaw:mainfrom
cyhhao:fix/codex-beta-features

Conversation

@cyhhao
Copy link
Copy Markdown
Contributor

@cyhhao cyhhao commented May 15, 2026

What

  • Preserve Codex-specific Responses headers, including X-Codex-Beta-Features, Version, turn metadata/state, window id, parent thread id, and installation id.
  • Infer x-codex-beta-features: remote_compaction_v2 when a Codex context_compaction item is present but an intermediate client/proxy omitted the header.
  • Pass X-Codex-Turn-State response headers back to Codex clients so later requests in the same turn can replay the sticky-routing token.
  • Add streaming coverage to ensure context_compaction SSE output items pass through unchanged.
  • Add coverage for both normal OpenAI forwarding and OpenAI passthrough forwarding.

Why

Recent Codex remote compaction v2 requests send context_compaction items through /v1/responses and advertise the protocol with x-codex-beta-features: remote_compaction_v2. Official Codex also sends a version header on Responses requests. If sub2api filters these headers, ChatGPT Codex backend can validate the request as a normal/older Responses payload and reject context_compaction as an invalid item type.

The v2 flow is streaming. Codex also captures x-codex-turn-state from the stream response headers and replays it on subsequent requests in the same turn. Preserving that response header keeps the v2 streaming contract intact.

Related issues

Some of the older reports also mention model mapping, fixed Codex version headers, or timeout/context-canceled behavior, so this PR intentionally references them as related rather than claiming to close all of them.

Test

  • go test ./internal/service
  • go test ./internal/util/responseheaders

Risk

Low. This extends existing Codex-specific allowlists and preserves the upstream SSE body shape; it does not rewrite request or response bodies.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@cyhhao cyhhao changed the title fix: preserve Codex beta feature header fix: preserve Codex Responses headers May 15, 2026
@cyhhao
Copy link
Copy Markdown
Contributor Author

cyhhao commented May 15, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 15, 2026
@cyhhao
Copy link
Copy Markdown
Contributor Author

cyhhao commented May 15, 2026

recheck

@cyhhao cyhhao closed this May 15, 2026
@047lovelife
Copy link
Copy Markdown

Hi, I’m also hitting this GPT-5.5 remote compact failure. I noticed #2494 seems related to preserving Codex Responses headers / remote_compaction_v2, but it was closed without being merged. Was that PR superseded by another fix, or was there a blocker with that approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants